#include "gameselect.h"
#include"gameroom.h"
#include<QIcon>
#include<QPushButton>
#include"gamehall.h"
#include<QSound>
#include<QPainter>
#include<QTextEdit>
#include<QFile>
#include<QTextStream>


GameSelect::GameSelect(QWidget *parent) : QWidget(parent)
{
    this->setFixedSize(1500,1000);//设置窗口大小
    this->setWindowIcon(QIcon(":res/ico.png"));
    this->setWindowTitle("游戏关卡选择");

    QPushButton* backBtn = new QPushButton(this);//返回按钮
    backBtn->move(1400,900);
    backBtn->setIcon(QIcon(":res/back.png"));
    backBtn->setShortcut(QKeySequence(Qt::Key_Escape));

    connect(backBtn,&QPushButton::clicked,[=](){
         this->close();
        GameHall * gameHall = new GameHall;
        gameHall->show();

        QSound::play(":res/clicked.wav");
    });

    QFont font("华文行楷",20);

    gameroom*gameRoom = new gameroom;

    QPushButton* simpleBtn = new QPushButton(this);
    simpleBtn->move(650,300);
    simpleBtn->setFont(font);
    simpleBtn->setText("简单模式");
    connect(simpleBtn,&QPushButton::clicked,[=](){
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();

        gameRoom->setTimeout(300);
    });

    QPushButton*normalBtn = new QPushButton(this);
    normalBtn->move(650,400);
    normalBtn->setFont(font);
    normalBtn->setText("正常模式");
    connect(normalBtn,&QPushButton::clicked,[=](){
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();

        gameRoom->setTimeout(200);
    });


    QPushButton*hardBtn = new QPushButton(this);
    hardBtn->move(650,500);
    hardBtn->setFont(font);
    hardBtn->setText("困难模式");
    connect(hardBtn,&QPushButton::clicked,[=]{
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();

        gameRoom->setTimeout(300);
    });


    QPushButton*hisBtn = new QPushButton(this);
    hisBtn->move(650,600);
    hisBtn->setFont(font);
    hisBtn->setText("历史战绩");


    connect(hisBtn,&QPushButton::clicked,[=](){
        QWidget *widget = new QWidget;
        widget->setWindowTitle("历史战绩");
        widget->setFixedSize(500,300);


        QTextEdit *edit = new QTextEdit(widget);
        edit->setFont(font);
        edit->setFixedSize(500,300);

        QFile file("C:/Users/zyy/Desktop/1.txt");
        file.open(QIODevice::ReadOnly);//读取内容

        QTextStream in(&file);
        int data =  in.readLine().toInt();//读取一行的数据

        edit->append("得分为:");
        edit->append(QString::number(data));//写入文本中

        widget->show();
    });

}

void GameSelect::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);//实例化画家对象
    QPixmap pix(":res/game_select.png");

    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
